package com.lfy.modules.blog.controller;

import com.lfy.modules.blog.domain.LeaveMessageEntity;
import com.lfy.modules.blog.domain.dto.leave.LeaveMsgAdminDTO;
import com.lfy.modules.blog.domain.dto.leave.LeaveMsgDTO;
import com.lfy.modules.blog.domain.vo.web.LeaveMsgAdminVO;
import com.lfy.modules.blog.service.LeaveMessageService;
import com.lfy.modules.common.anno.AutoUser;
import com.lfy.modules.common.domain.PageResultVO;
import com.lfy.modules.common.domain.R;
import com.lfy.modules.common.domain.entity.UserEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/leave")
public class LeaveMsgManagementController {
    @Resource
    private LeaveMessageService leaveMessageService;
    @RequestMapping("/list")
    public R<PageResultVO<LeaveMsgAdminVO>> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                 @AutoUser UserEntity user) {
        return leaveMessageService.getLeaveMsgByAdmin(pageNum, pageSize, user);
    }
    @RequestMapping("/delete/{id}")
    public R<Void> delete(@PathVariable("id") Long id, @AutoUser UserEntity user) {
        return leaveMessageService.deleteLeaveMsg(id, user);
    }
    @RequestMapping("/reply")
    public R<Void> reply(@RequestBody @Validated LeaveMsgAdminDTO dto, @AutoUser UserEntity user) {
        return leaveMessageService.replyLeaveMsg(dto, user);
    }
    @RequestMapping("/children")
    public  R<List<LeaveMsgAdminVO>> children(@RequestParam(value = "id") Long id){
        return leaveMessageService.getChildrenLeaveMsg(id);
    }
}
